<?php
class pro_mitraa_model extends MY_Model {
	var $model = 'pro_mitra';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT 
					a.kode_mitra,a.nama_mitra,a.alamat_lengkap,a.no_telp,a.no_fax,a.jenis_usaha,a.npwp,a.jenis_produk,a.website,a.email,
					b.kode_pemilik,b.nama_pemilik,b.kode_mitra,b.alamat,b.no_telp,b.no_hand,b.no_facsimile,b.website,b.email,
					c.no_kontrak,c.tanggal_kontrak,c.awal_kerja,c.akhir_kerja,c.fee_mitra,c.biaya_katalog,c.kode_mitra,
					d.no_rekening,d.nama_bank,d.atas_nama_mitra,d.kode_mitra,

					FROM pro_mitra a 
                    INNER JOIN pro_pemilik_mitra b ON a.kode_mitra = b.kode_mitra 
                    INNER JOIN pro_kontak_kerjasama_mitra c ON a.kode_mitra = c.kode_mitra
                    INNER JOIN pro_bank_mitra d ON a.kode_mitra = d.kode_mitra                
                    WHERE	(a.kode_mitra LIKE '%".post('keyword')."%')
					ORDER BY ".(post('sort')=='' ? 'a.kode_mitra' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_mitra', $arr_data);
		//$this->db->insert('pro_pemilik_mitra', $arr_data2);
		//$this->db->insert('pro_ktr_kerjasama_mitra', $arr_data3);
		//$this->db->insert('pro_bank_mitra', $arr_data4);
	}
		
	function Add2($arr_data2){
		//$this->db->insert('pro_mitra', $arr_data);
		$this->db->insert('pro_pemilik_mitra', $arr_data2);
		//$this->db->insert('pro_ktr_kerjasama_mitra', $arr_data3);
		//$this->db->insert('pro_bank_mitra', $arr_data4);
	}
	function Add3($arr_data3){
		//$this->db->insert('pro_mitra', $arr_data);
		//$this->db->insert('pro_pemilik_mitra', $arr_data2);
		$this->db->insert('pro_kontak_kerjasama_mitra', $arr_data3);
		//$this->db->insert('pro_bank_mitra', $arr_data4);
	}
	function Add4($arr_data4){
		//$this->db->insert('pro_mitra', $arr_data);
		//$this->db->insert('pro_pemilik_mitra', $arr_data2);
		//$this->db->insert('pro_ktr_kerjasama_mitra', $arr_data3);
		$this->db->insert('pro_bank_mitra', $arr_data4);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_mitra', $arr_data, $arr_rule);
	}
	
	function Update2($arr_data2, $arr_rule2){
		$this->db->update('pro_pemilik_mitra', $arr_data2, $arr_rule2);
	}
	
	function Update3($arr_data3, $arr_rule3){
		$this->db->update('pro_kontak_kerjasama_mitra', $arr_data3, $arr_rule3);
	}
	
	function Update4($arr_data4, $arr_rule4){
		$this->db->update('pro_bank_mitra', $arr_data4, $arr_rule4);
	}
	
	function GetSingle($as_kode_mitra){
		$result = $this->db->get_where('pro_mitra', array('kode_mitra' => $as_kode_mitra));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_kode_mitra)
	{
		$result = $this->db->get_where('pro_mitra', array('kode_mitra' => $as_kode_mitra));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_mitra WHERE kode_mitra = '".$arr_rule['kode_mitra']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_mitra']."]<br />";
			}else{
				$this->db->delete('pro_mitra', array('kode_mitra' => $arr_rule['kode_mitra']));
				$this->db->delete('pro_pemilik_mitra', array('kode_mitra' => $arr_rule['kode_mitra']));
				$this->db->delete('pro_kontak_kerjasama_mitra', array('kode_mitra' => $arr_rule['kode_mitra']));
				$this->db->delete('pro_bank_mitra', array('kode_mitra' => $arr_rule['kode_mitra']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>